package com.koron.common.core.business.workflow.bean.dto;

import com.alibaba.fastjson.JSONObject;
import com.koron.common.core.business.workflow.bean.result.User;
import com.koron.common.core.business.workflow.util.TextUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author jzp
 * @since 2022/1/11
 */
@ApiModel(value = "提交后的返回实体类", description = "SubmitUserDTO")
public class SubmitUserDTO {
    private static final String USER_KEY = "EAM_USER";

    /**
     * 需要将用户信息展示到前端提交页面
     */
    @Getter
    @Setter
    @ApiModelProperty(value = "需要将用户信息展示到前端提交页面")
    private List<User> users;

    /**
     * 前端需要根据这个重置formVariables的值
     */
    @Setter
    @ApiModelProperty(value = "前端需要根据这个重置formVariables的值")
    private String formVariables;

    public String getFormVariables(){
        Map<String, String> map = TextUtil.toMapFromString(this.formVariables);
        map.put(USER_KEY, users.stream().map(User::getCode).collect(Collectors.joining(",")));
        return JSONObject.toJSONString(map);
    }
}
